Copyright: © 1997 by Gerard Stoffels CIS : 75542,610


LPTGrd - Print Component for InfoPower 2.03 grids
LPTGrd / LPTBGrd- DbGrid Print Component

Works with Borland and InfoPower 2.03 grids

VCL-Components for Borland Delphi 1, 2 & 3

Version 1.0

Registration and Support

Author : Gerard Stoffels

E.mail :  75542,610@Compuserve.com

CIS :       75542,610

Installation

Introduction

Quick Start

Properties and Methods

Organizing the Printed Output

Improvements over the Demo version

Disclaimer

This software and all accompanying files are provided ‘As Is’ and without warranties as to performance and merchantability or any other warranties wether expressed or implied. No

warranty of fitness for a particular purpose is offered.

InfoPower and Borland Delphi are registered trademarks of their respective owners who are in no way responsible for any damage, loss of profit, in ANY way in conjunction with the use of this software.


Installation

Install LPTgrd1.Pas/dcr and LPTBgrd1.Pas/dcr for Delphi 1

Install LPTgrd2.Pas/dcr and LPTBgrd2.Pas/dcr for Delphi 2

Install LPTgrd3.Pas/dcr and LPTBgrd3.Pas/dcr for Delphi 3

ADD  THE  LPTDEFS  AND PRINTERS UNITS  TO THE USES CLAUSE IN THE IMPLEMENTATION PART OF YOUR APPLICATION  !!!

Note : The *.dcr files hold the compnent palette icon resources.

Install LptGrd as any other Delphi component. Make sure you copied the LptGrdX.dcu and LptGrdX.Dcr files to your library path. Installation defaults to the «Samples» page on your Component Palette.

You should have the following files:

For InfoPower grids :

LPTgrd1.Pas	Source unit with the LPTgrd component

LPTgrd1.DCR	Delphi compiled resource with the palette icon

LPTgrd2.Pas	Source unit with the LPTgrd component

LPTgrd2.DCR	Delphi compiled resource with the palette icon

LPTgrd3.Pas	Source unit with the LPTgrd component

LPTgrd3.DCR	Delphi compiled resource with the palette icon

For Borland grids :

LPTBgrd1.Pas	Source unit with the LPTgrd component

LPTBgrd1.DCR	Delphi compiled resource with the palette icon

LPTBgrd2.pas	Source unit with the LPTgrd component

LPTBgrd2.DCR	Delphi compiled resource with the palette icon

LPTBgrd3.Pas	Source unit with the LPTgrd component

LPTBgrd3.DCR	Delphi compiled resource with the palette icon

For both types : LPTDEFS.Pas  type definitions

(The compiled units *.DCU files come along with the package, but it is preferred that you recompile on your system due to version differences on the InfoPower components).

Help file :

LPTgrd.HLP	This help file

LPTgrd.HPJ	Use this to generate a keyword file (LPTgrd.KWF)

LPTGrd.CNT	Adds a contents tab

Readme.txt	A short notice


Quick Start

The fastest way to get LPTgrd to work is to drop it onto a form containing an InfoPower grid and to set the wwGrid property of the component to the name of the grid. The Object Inspector automatically will show all the InfoPower grids available. Then drop a TButton on the form and attach the following code to its onClick event handler:

...

LPTgrd1.Print ;               or call PrintExclude(x,y)

...

Thats all !!

Call  LPTGrd1.Abort if you want to stop the printing. The abort will be immediate if the printer is still recieving data. If it has started printout already, the abort will occur at the end of the page currently getting ready to be sent to the printer.

Fine Tuning Print :

You will notice that your grid is scrolling during spooling. To avoid this you should call the DisableControls method of the grids Datasource. Dataset, whatever this could be. You also should  bookmark the datasource before printing. Don’t forget to free the bookmark after calling EnableControls.

DO  NOT  USE ENABLE/DISABLECONTROLS WITH THE PRINTEXCLUDE METHOD !

This method calls the above methods internally. If you would disable controls before calling it the grid itself becomes disabled and columns no longer can be hidden !

You now may want to reset borders, Date labels, etc.

Note:

Margins settings are very precise. If you notice that there is a slight difference between the left and the right margin then this is normal. The internal code only retrieves single values for left/right and top/bottom offsets. On some printers these values can differ between left and right, top and bottom. Differences are in the range of less than 1/10th of an inch.


Introduction

TLptGrd is a grid printer for InfoPower wwDBGrids.

TLptBGrd is a grid printer for Borland DBGrids.

It saves the developer a great deal of time by scaling the output to the target printing area. All layout parameters can be set at run time. Standard default settings permit a complete printout of the data with a single line of code. The component uses the text alignment settings of the source grid.

The default behavior can be summarized as follows

•	The visible columns of the underlying grid only get printed

•	Moving Columns impacts on the printout

•	The columns scale to their displayed width on the grid

•	All margins  default to 1 inch

•	The output occurs on a full page in landscape display inside the default margins

•	Automatic page change  is performed as the data are printed

•	Row sizing and wordwrap settings are those of the the source grid (set RowHeightPercent for Borland grids)

•	A Standard Printer Setup Dialog allows to set parameters

•	The Column headers and details align as seen in the respective grids

In addition you can:

•	Modify the output area by setting the page margins

•	Set Page Orientation as you which at design or runtime

•	Switch On/Off the PrinterDialog at design or runtime

•	Set FromPage and ToPage at design time and at runtime

•	Display Page Number and Date with custom labels at 6  different locations

•	Display a Heading on all pages or just on the first page

•	Align the Heading as you want

•	Individually set fonts for Heading, ColTitle and Detail data

•	Abort the printing process  before, during and after spooling

•	Apply precise page numbering and selection based on rowsize

•	Set Borders in inches, millimeters and points

•	Turn on/off of Column and/or Rowlines

•	Draw a Border line around the data if you don’t draw ColLines or RowLines

IMPORTANT:

THIS IS A RELEASE VERSION. IF YOU HAVE ANY TROUBLE, PLEASE LET ME KNOW. YOU ARE ENTITLED FOR A FREE UPDATE AS SOON AS INFOPOWER 3.0 FINAL RELEASE COMPONENTS START SHIPPING. THIS VERSION USES THE PRERELEASE VERSION A.

See Registration and Support


Properties and Methods

TLPTgrd descends from TComponent. It has all the inherited properties plus the following as you find them in the object inspector. This help file does not mention the inherited properties. You can find information on these properties in the Delphi online Help.

ALL PROPERTIES ARE COMMON TO BOTH COMPONENTS (EXCEPT ROWHEIGHTPERCENT WHICH IS UNIQUE TO LPTBgrdX ).

Published Properties

Border

BottomMargin

ColLines

ColTitleAlignment

ColTitleBackColor

ColTitleFont

DateLabel

DatePos

DetailBackColor

DetailFont

EndPage

FromPage

Heading

HeadingAlignment

HeadingFont

HeadingRepeat

LeftMargin

Orientation

NoteA,NoteB

PageHeaderLine

PageLabel

PageLabelPos

PrintDlg

RightMargin

RowHeightPercent

RowLines

TopMargin

Units

wwGrid

Methods

Preview

Print

PrintExclude(x,y)

Abort


Methods

The LPTGRD components only print visible columns. Tho prevent a column from printing, remove it from the field list of the table fields editor.

Print	(virtual)

The Print method starts the actual printout of the table with the parameters set in the Object Inspector or with those coded before a call to print was made. You should bookmark and call DisableControls before printing.

PrintExclude(x,y:integer); (virtual)

This method hides the columns x to y. If you have a table with many columns, the scaling process may reduce the column widths so far that the contents are no longer visible. You must in that case print to 2 or more pages. As an example :

Your table has 10 columns. Thecolumn numbers are 0 to 9. To print columns  7 to 10 you would write :

PrintExclude(0,6);

PrintExclude is mainly used to prevent the last columns or the first columns from printing. But you can also hide central columns with this method.

The temporailly hidden columns will be restored after printing.

DO NOT USE  DISABLECONTROLS  BEFORE  CALLING  THIS  METHOD: THIS IS DONE INTERNALLY !!

Abort (virtual)

You can call the Abort method at any time during print. The abort method writes to an internal variable FGridAborted, a boolean,  which is checked before the component  calls the Printer.NewPage method.

FGridAborted can be accessed through the setting of GridAborted.

GridAborted is a public property  (read and write)

The internal code for the Abort method is :

procedure TLPTgrd.Abort;

 begin

   FGridAborted:=TRUE;

  end;

end;

Writing LPTgrd.GridAborted:=TRUE has the same effect as LPTgrd.Abort.

The Create and Destroy methods are overridden inherited methods of TComponent.


BackColor Settings

Applies to :

DetailBackColor : Tcolor

ColTitleBackColor : Tcolor

These settings determine whether the column titles and/or the detail cells will have a backcolor. The default setting is clWhite. You may use these settings on both Laser and Inkjet printers provided they offer a resolution of 300 dpi at least.

For b/w Laser printers settings of clAqua or clSilver give good results. You can also use custom settings by transforming RGB values to Tcolor values.


Border:Boolean (Default : TRUE)
Border : Boolean (Default  TRUE)

If set to TRUE the printed grid, including the ColTitles, will be surrounded by a single line. A  combination of RowLines (TRUE) and Border (TRUE) draws only row lines and a border. The last printed record is followed by a line, thus terminating the printout. The default setting is TRUE.

If ColLines is TRUE then a border is drawn automatically around the data even if Border is set to FALSE.


BottomMargin : Single

Expressed in units of inches, millimeters or points, this value indicates the distance from the physical page bottom to the bottom of the last printable line of text. Nothing ever can be printed on this area.  Laser printers (and others) cannot print to the entire surface of a sheet of paper. There is always a little gap of 5-6 MM  (about ¼ of inch) at the bottom, top and on both sides. If  BottomMargin is less than this offset then the BottomMargin will map to this offset value in order to assure that no data are lost on the output. The LPTgrd component  even uses a more restrictive setting if the printing of the last line is coiinciding with this value.


ColLines : Boolean (Default :TRUE)

ColLines is a boolean value. If set to TRUE, vertical separator lines are drawn between each column except for the outer columns where a border is drawn. That means that you cannot draw vertical lines (ColLines) without drawing a border. But you can very well draw a border without drawing ColLines.


ColTitleAlignment

FOR  BORLAND  GRIDS  ONLY !!

This property simulates the behavior of the InfoPower Title properties. You do not need to use the Tilde sign to indicate a word break. The titles will apply wordbreak on the space character. This property is available only when RowHeightPercent of LPTBGRD is mpore then 100.

A future release will introduce the ColTitleLines property.


ColTitleFont : TFont

The font used to print the Column Headers of the grid. By default the ColTitleFont is set to the same font as DetailFont except for the style setting.

ColTitleFont.Name:= ‘Arial’;

ColTitleFont.Size:=9 ;

ColTitleFont.Style:= [fsBold] ;

Here is how you would change the setting in code:

.....

var

Afont : Tfont;

 begin

  Try

  Afont:=TFont.Create;

    Afont.Assign(LPTGrd.ColTitleFont);

    Afont.Size:=10;

    Afont.Style:= [fsBold] ;

    LPTGrd.ColTitleFont.Assign(Afont);

  Finally

   Afont.Free;

end;

end;

Another way to change the font is to simply use a TFontDialog object :

...

With TFontDialog.Create(self) do begin

   LPTGrd.ColTitleFont.Assign(Font);

   Free;

end;

...

P.S. : Writing ColTitle.Font will raise an exception


DateLabel : String

Default : ‘Date : ‘

The string goes with the date. Please note that if default settings are used, the date with its label is not printed as the default setting for DatePos is ppNone.

Ex:

Today is :

Redmond :

Sunshine day :

If defined that way, and with a DatePos other than ppNone, LPTGrd would write the date as:

Today is : 5/20/1997

Redmond : 20.05.97

Sunshine day : 20-05-1997

The default date format of the Windows 95 setup is used.


DatePos : TPagePos

Default : ppNone

The Date itself is the date of printing.

The DatePos determines where the Date is written. The values used are of

Type TPagePos = (

ppNone,	no Date is written

ppTopLeft,	on top of the Column Titles to the left

ppTopCenter,	centered on top of the Column Titles

ppTopRight,	on top of the Column Titles to the right

ppBottomLeft,	one line before the BottomMargin to the left

ppBottomCenter,	centered one line before the BottomMargin

ppBottomRight,	one line before the BottomMarin to the right

)

Whenever nothing is written to ppTopXXX  the line on top of the column titles will be suppressed in order to use it for data output. A  space of half the height of Heading is inserted between the Heading and the grid section. If no Heading is used in addition to the above, the component will start to print at the TopMargin.

See : Organizing the Printed OutputOrganizing_the_Printed_Output for further tips


DetailFont : TFont

The font used to write the detail part of the table. By default this font is set to:

DetailFont.Name:=’Arial’

DetailFont.Size: 8;

DetailFont.Style:= := [ ];

The DetailFont size determines the number of RowLines and further influences Page Numbers. Modifying the size of the DetailFont will naturally impact on the number of records written per page. The default column scaling is also based on this font. As a general rule you, as the programmer should select fonts, for ColTitleFont and DetailFont,  that do not differ too much in horizontal extent.

ColTitleFont for an example on how to change the font by code;


EndPage : Integer

This value indicates the last page to be printed. If different DetailFont settings are used on consecutive prints the EndPage will contain slightly different records.


FromPage : Integer

This value indicates the first page to be printed for a given DetailFont.Size. If you modify the DetailFont Size on consecutive prints, the system will correctly print  starting at FromPage but the page most probably will start on a different record.


Heading : String

The Heading is the title of your printout. If a Heading is specified it is always printed on the first page of the report. Unless you set Heading to an empty string, you cannot prevent printing it on the first page. Printing of Heading can be supressed on consecutive pages by setting the HeadingRepeat property to false.


HeadingAlignment : TAlignment

HeadingAlignment refers to where the Heading is written horizontally. There are three (3)

possible values for TAlignment:

taLeftJustify	The Heading is printed at the LeftMargin

taRightJustify	The Heading is printed until the RightMargin

taCenter	The Heading is centered between the LeftMargin and the

 RightMargin

HeadingAlignment is independant from the physical page size. The Heading is clipped if it exceeds the printable area between the page borders.

See : Organizing the Printed Output for further tips.


HeadingFont : TFont

The font used to write the Heading of the table. By default this font is set to:

HeadingFont.Name:=’Arial’

HeadingFont.Size:=18;

HeadingFont.Style:= := [fsBold ];

Setting high values for the HeadingFont.Size can significantly reduce the number of records per page as printing real estate is lost. With the default settings the Heading by itself takes up three (3) detail lines. If you the use a PageLabel and a DateLabel on different rows another 4 lines are lost.

See : Organizing the Printed Output for further tips.


HeadingRepeat : Boolean

With this boolean property you can decide whether you want to repeat the Heading on each

page or not. By default the setting is TRUE.


LeftMargin : Single

The physical distance from the left edge of the paper to the first printable character on a line.

Expressed in units of inches, millimeters or points, depending of the setting of Units. Internally these values represent:

1 inch = 25.4 mm = 72 points

See also BottomMargin


NoteA, NoteB

Two additional strings that go either ontop of the column titles or underneth the detail section. You can display with these two strings any additional data like Department Name or Server Name etc.

By default these strings are empty. They can occupy any position specified by NoteAPos and NoteBPos.

The position indications are the same as those used for the date label and the page number label: TPagePos.

If PageFooterLine is True, these labels are positioned one line underneath. If PageHeaderLine is true, they sit directly ontop of it.


Orientation : TPrinterOrientation

Possible values are :

poLandscape	for printer orientation Landscape

poPortrait	for printer orientation Portrait

The orientation of the printed report depends on how the print process is started:

If PrintDlg is  TRUE  a Standard Printer Dialog appears after a call to the components Print method. If the user accepts the settings, the Orientation setting as shown in the Printer Setup Dialog is used. That means that the orientation of the Windows printer is used.

If PrintDlg is set to FALSE, no Printer Dialog appears. The Delphi Printer Object is then initialized to the Orientation value of LPTgrd as set in the object inspector or set in code.


PageFooterLine

Type : boolean

A line that separates the detail section from the footer section. If set to TRUE this line will appear ONE LINE above the eventual page number, date or notes written at the ppBottomXXX positions. In addition to this it will only show if the detail section itsel does not reach the page footer. That means that in most cases it will only serve on the last page of the printout. It could very well show up on pages where the RowHeightPercent is greater then 100. In these cases the component evaluates the space and draws the line in accordance.


PageHeaderLine

Type : boolean

If set TRUE, the component draws a line that separates the page header section from the detail section .

Note : The line will not appear if the page has nothhing written to the ppTopXXX positions.

(Date, page number, notes etc..)


PageLabel : String

A string associated with the page number. The default setting is ‘Page : ‘

The printout would the be formatted to :  Page : 7

Setting the PageLabel property to ‘You are now reading page  ‘ would print :

You are now reading page 7

As already mentioned for the DatePos property, a PageLabel is not printed when the PageLabelPos is ppNone.

NOTE : Page numbers are handled internally

See : Organizing the Printed Output for further tips.


PageLabelPos : TPagePos

The PageLabelPos property indicates to where the page label is written. The default value is ppNone, which means that no page label is written, although the PageLabel is evaluated internally and can be retrieved in code. The TPagePos type is defined as :

Type TPagePos = (

ppNone,	nothing is written

ppTopLeft,	on top of the Column Titles to the left

ppTopCenter,	centered on top of the Column Titles

ppTopRight,	on top of the Column Titles to the right

ppBottomLeft,	one line before the BottomMargin to the left

ppBottomCenter,	centered one line before the BottomMargin

ppBottomRight,	one line before the BottomMarin to the right

)


Preview

Preview allows to rapidly see the grid you have on screen. The settings of the Object Inspector are used. If the setting for Destination is dPrinter, the Preview method will set it to dPreview during the preview process and restore the old setting when leaving the procedure.

NOTE : Setting PrintDlg to true has no effect when preview is called.

If the setting in the Object Inspector is dPreview, a call to Print will Preview the grid.


PrintDlg : Boolean (Default :TRUE)
PrintDlg : Boolean (Default TRUE)

A boolean value which determines whether a Standard Printer Dialog is shown before starting the print process. If set to TRUE a Printer Dialog is created at runtime. The component frees the Dialog after it is done with it. The call to PrinterDialog.Free is made inside a Try...Finally ...End block to avoid memory leakage, and you as the developer do NOT have to worry about this.

IMPORTANT: You can call your own PrinterDialog if PrintDlg is FALSE. Look at the following code:

...

with wwDbGrid1.Datasource.Dataset do begin

 BM:=GetBookmark;

 DisableControls;

 with TPrintDialog.Create(self) do

   begin

    if execute then

     LPTGrd.Print

    else

     free;

  end;

GotoBookMark(BM);

FreeBookMark(BM);

EnableControls;

end;

...

Executing this code while PrintDlg is TRUE will generate a second Printer Dialog !


RightMargin : Single

The physical distance from the right paper edge to the last printable character on a  row.

Expressed in units of inches, millimeters or points, depending of the setting of Units.

See also BottomMargin


RowHeightPercent

FOR BORLAND GRIDS ONLY!

This property is provided by the InfoPower wwDbgrid. As it lacks on the Borland Dbgrid, the LPTBgrd component introduces it. Setting the value to more then 100 will trigger wordwrap in the columntitles and row cells. It is not possible to set less then 100 %. You should also avoid setting less than multiples of 100. If you set RowHeightPercent to 200, there will be enough room for 2 lines to fit, provided they contain empty spaces.

The component detects the RowHeightPercent setting of the InfoPower grid.


RowLines : Boolean

Default setting is TRUE.

After printing a row of data the component draws a line at a distance of 20% of the textheight used for the printed text.

See ColLines for additional info


TopMargin : Single

Expressed in units of inches, millimeters or points, this value indicates the distance from the physical page top to the Top of the first printable line of text. Nothing ever can be printed on this area.  Laser printers (and others) cannot print to the entire surface of a sheet of paper. There is always a little gap of 5-6 MM  (about ¼ of inch) at the bottom, top and on both sides. If TopMargin is less than this offset then The TopMargin will map to the offset value.

See BottomMargin for additional info


Units : TUnits

The definition of the type is :

Type TUnits=(uInches,uMMs,uPoints);

By setting the Units to one of these three values the Margins are calculated in terms of the selected unit.

That is either :

Inches

Millimeters

Points

Remember that 1 inch is 25.4 millimeters or 72 points.

Units is uInches by default . If you change the settings from uInches to uMMs, the default settings for the margins will not be modified. An initial setting of one inch will be set as one millimeter. This forces the component to apply the margin settings to the unprintable area. So, after setting the Units in the Object Inspector, always check wether your Margins will be set correctly with the new Units.


wwGrid : TwwDBGrid

This property is named GRID on the Borland version.

wwGrid is the grid to which LPTgrd is attached. LPTgrd does not produce a copy of the grid (overhead !!). Instead it uses a pointer to the grid object itself. Setting wwGrid to nil just undocks from the grid, leaving it in place. You cannot assign the grid to wwGrid :

This would produce an exception:

wwGrid.Assign(wwDBGrid1) . Remember that Assign is used together with object instances.

The reason is that wwGrid (or better the internal storage of wwGrid) is a pointer to an object but not an instance of that class. The size of wwGrid is 4 bytes .

wwGrid is talking to a private variable FwwGrd which is set to nil before the object (component) is removed from memory .

Suppose you have 2 wwDBGrids on you form. The following code allows to change the wwGrid property of LPTgrd.

 .....

begin

 If LPTGrd.wwGrid=wwDBGrid1 then

   LPTGrd.wwGrid:=wwDBGrid2

else

   LPTGrd.wwGrid:=wwDBGrid1;

end;

......

Changing forth and back, a printout would either print the data of one grid or the other. In such a case you would have to modify the Heading of the LPTgrd component at runtime. Rescaling occurs before each printout.


Organizing the Printed Output

Basic Procedures :

In the Object Inspector do the following

Set the name of the InfoPower / Borland grid

Set the units you want to use for the margins.

Set margins in terms of the units you selected.

Set the position of The Date Label and the Page Number Label (ppTopLeft,ppBottomRight...)

Set HeadingAlignment

Set The HeadingRepeat option

Set Orientation (Landscape is recommended for grids with many columns)

Set the RowLines and ColLoines options ( and Border)

Saving Paper Real Estate :

As the DateLabel and PageLabel can be printed on a single row, you can save at least 3 lines for detail output. Best results are obtained if these values are set to ppTopxxx. Just pay attention not to assign identical values if you are printing on the same line.

Scaling output for the paper:

Set the font sizes for detail and column titles. Selecting excessif font sizes may result in text being clipped. Good font sizes for output on paper are 9 and 8. With a detail font size set to 9 a reasonable amount of letters will fit to a page even if your screen is too narrow to display all the columns. Best results are obtained if the column headers use the same font size as the detail font. You may choose Bold face types for the column headers.

The component uses proportional scaling. There is no need to reduce the visible column width for each column individually. If all the column are similar in width, they will all be scaled down by the same scaling factor.


Improvements on the Demo version
Improvements over the Demo version

- 3. Setting numbers of copies.

The setting of the number of copies did not work correctly under Delphi 1. This has been fixed with this release.

- 2. Hiding columns.

If you were hiding columns the printout correctly showed the column headings but still was printing the underlying data of hidden columns. This has been fixed. Technically the components do not print what is in the dataset but what is in the grid cells.

-  3. Previewing

An increasing number of users have requested the possibility to preview output. This preview will be available for the release scheduled for the 21st of june. As a registerd user you will receive this version for free.


Registration and Support

As a registered user you may use these components without any royalties as part of their commercial or non-commercial applications. It is fair not distribute the components themselves. Please report any bug or suggestion to me. Suggestions are always wellcome and will be implemented whenever possible.

Author : Gerard Stoffels

E-mail :  75542,610@Compuserve.com

CIS :       75542,610

Fax : (Luxembourg-Europe) 00352 - 50 90 58